package com.xzone.material.security.controller

import org.springframework.security.authentication.UsernamePasswordAuthenticationToken
import org.springframework.security.config.annotation.authentication.configuration.AuthenticationConfiguration
import org.springframework.security.core.context.SecurityContextHolder
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.RequestBody
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController
import kotlin.reflect.jvm.internal.impl.load.kotlin.JvmType


@RestController
@RequestMapping("security")
class SecurityController(val configuration: AuthenticationConfiguration) {
//    @PostMapping("login")
//    fun login(@RequestBody params: Map<String, Any>): String {
//        try {
//            val authenticationManager = configuration.authenticationManager
//            val token = UsernamePasswordAuthenticationToken(params["username"], params["password"])
//            val authenticate = authenticationManager.authenticate(token)
//            SecurityContextHolder.getContext().authentication = authenticate
//
//            return "登录成功"
//        } catch (e: Exception) {
//            e.printStackTrace()
//            return "登录失败"
//        }
//    }

//    @PostMapping("logout")
//    fun logout(@RequestBody params: Map<String, JvmType.Object>): String {
//        return "logout"
//    }
}